package com.pan.common.init;

import com.pan.service.Myservice;
import com.stark.service.SpringFactoriesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Slf4j
public class InitAfterStart  implements ApplicationRunner{


    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("在spring启动后，进行操作");
        printAllApplicationBean();
    }


    public void printAllApplicationBean(){
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        log.info(String.format("%s,", Arrays.asList(beanDefinitionNames)));
        Myservice bean = applicationContext.getBean(Myservice.class);
        bean.learnEnable();
        SpringFactoriesService bean1 = applicationContext.getBean(SpringFactoriesService.class);
        bean1.sayHello();

    }

}
